$(function(){
	var param = $("#tabContent > .tab-pane.active").data(); //获取上级页面的参数
	paramTabPage[tabId] = jQuery.extend(true, {}, param);
	$("[role='tabpanel']").each(function(i,n){
		$(n).addClass('testCon');
	});
	$(document).ajaxStop(function(){
			drgUI.tips();
	})
	
	var quotas=[];
	if (param.compareType == "none") {
		quotas = [ {
			code : "InCaseCnt",
			name : "入组病例数",
			isLink : "1"
		}, {
			code : "AvgFee",
			name : "次均费用",
			isLink : "0"
		}, {
			code : "DrugRatio",
			name : "药占比(%)",
			isLink : "0"
		}, {
			code : "CMI",
			name : "CMI值",
			isLink : "0"
		} ]
	} else {
		quotas = [
				{
					code : "InCaseCnt",
					name : "入组病例数",
					isLink : "1"
				},
				{
					code : "AvgFee",
					name : "次均费用",
					isLink : "0"
				},
				{
					code : "DrugRatio",
					name : "药占比(%)",
					isLink : "0"
				},
				{
					code : "CMI",
					name : "CMI值",
					isLink : "0"
				},
				{
					code : "ExcessCnt_F",
					name : (param.compareType == 'manage' ? "费用超标[绩效]病例数"
							: (param.compareType == 'std' ? "费用超标[标杆]病例数"
									: "费用超标[院内均值]病例数")),
					isLink : "1"
				}, // 根据不同比较类型显示不同描述
				{
					code : "SpecificCnt_F",
					name : "费用特异病例数",
					isLink : "1"
				}, {
					code : "AvgFee_F",
					name : "矫正次均费用",
					isLink : "0"
				}, {
					code : "DrugRatio_F",
					name : "矫正药占比",
					isLink : "0"
				} ]
	}

	var depQuotas=[];
	if (param.compareType == "none") {
		depQuotas = [ {
			code : "InCaseCnt",
			name : "入组病例数",
			isLink : "1"
		}, {
			code : "AvgFee",
			name : "次均费用",
			isLink : "0"
		}, {
			code : "DrugRatio",
			name : "药占比(%)",
			isLink : "0"
		}, {
			code : "CMI",
			name : "CMI值",
			isLink : "0"
		} ]
	} else {
		depQuotas = [
				{
					code : "InCaseCnt",
					name : "入组病例数",
					isLink : "1"
				},
				{
					code : "AvgFee",
					name : "次均费用",
					isLink : "0"
				},
				{
					code : "AvgFeecc",
					name : (param.compareType == 'manage' ? "次均费用[绩效]"
							: (param.compareType == 'std' ? "次均费用[标杆]"
									: "次均费用[院内均值]")),
					value: param.typeOne,
					isLink : "0"
				},
				{
					code : "DrugRatio",
					name : "药占比(%)",
					isLink : "0"
				},
				{
					code : "DrugRatiocc",
					name : (param.compareType == 'manage' ? "药占比(%)[绩效]"
							: (param.compareType == 'std' ? "药占比(%)[标杆]"
									: "药占比(%)[院内均值]")),
					value: param.typeTwo,
					isLink : "0"
				},
				{
					code : "CMI",
					name : "CMI值",
					isLink : "0"
				},
				{
					code : "ExcessCnt_F",
					name : (param.compareType == 'manage' ? "费用超标[绩效]病例数"
							: (param.compareType == 'std' ? "费用超标[标杆]病例数"
									: "费用超标[院内均值]病例数")),
					isLink : "1"
				}, // 根据不同比较类型显示不同描述
				{
					code : "SpecificCnt_F",
					name : "费用特异病例数",
					isLink : "1"
				}, {
					code : "AvgFee_F",
					name : "矫正次均费用",
					isLink : "0"
				}, {
					code : "DrugRatio_F",
					name : "矫正药占比",
					isLink : "0"
				} ]
	}
	
	var legend = [param.depName];
	var xdata_avgdays = [];
	var xdata_avgfee = [];
	var seriesdata_avgdays = [];
	var seriesdata_avgfee = [];
	var ajaxCount = quotas.length*3;
	getTableData("Base", "dep", "hosp",function(data){
		var columns = [];
		var datas = [];
		datas = datas.concat(data);
		concatTableData(depQuotas, datas, "depQuota_AvgFeeDrugRatio-table", columns, "dep",  "hosp",function(table){
			var param_t = drgUI.setAjaxData(tabId);
			param_t.monitorType = "dep";
			getTrendData(param_t, "AvgFee", function(data_0){
				var seriedata_avgdays = {type: "line", clickable:false,smooth: true, symbol:"none", name: param.depName, data:[]};
				for(o in data_0){
					xdata_avgdays.push(data_0[o].ddesc);
					seriedata_avgdays.data.push(data_0[o].QuotaValue?data_0[o].QuotaValue:0);
				}
				seriesdata_avgdays.push(seriedata_avgdays);
				loadTrendChart("次均费用", xdata_avgdays, seriesdata_avgdays, legend, $("#"+tabId+" #lineChart-1"));
				loadTrendChart("次均费用", xdata_avgdays, seriesdata_avgdays, legend, $("#"+tabId+" #lineChart-3"));
			})
			getTrendData(param_t, "DrugRatio", function(data_1){
				var seriedata_avgfee = {type: "line", clickable:false,smooth: true, symbol:"none", name: param.depName, data:[]};
				for(o in data_1){
					xdata_avgfee.push(data_1[o].ddesc);
					seriedata_avgfee.data.push(data_1[o].QuotaValue?data_1[o].QuotaValue:0);
				}
				seriesdata_avgfee.push(seriedata_avgfee);
				loadTrendChart("药占比(%)", xdata_avgfee, seriesdata_avgfee, legend, $("#"+tabId+" #lineChart-2"));
				loadTrendChart("药占比(%)", xdata_avgfee, seriesdata_avgfee, legend, $("#"+tabId+" #lineChart-4"));
			})
		});
		
	})
	
	getTableData("Base", "clinic", "dep", function(data){
		var columns = [{"data": "ddesc"}];
		var datas = [];
		datas = datas.concat(data);
		concatTableData(quotas, datas, "groupTable-table", columns, "clinic","dep", function(table, oSetting){
			var seriesdata_avgdays_copy = jQuery.extend(true, [], seriesdata_avgdays);
			var seriesdata_avgfee_copy = jQuery.extend(true, [], seriesdata_avgfee);
			var legend_copy = jQuery.extend(true, [], legend);
			var aoData = oSetting.aoData;
			table.find("tbody tr").each(function(i,n){
				$(n).find("td:last a").unbind();
				$(n).find("td:last a").click(function(){
					var rowIndex = $(this).attr("data-rowindex");
					if($("#"+tabId+" #lineChart-1 img").size()>0 || $("#"+tabId+" #lineChart-2 img").size()>0) return;
					if(seriesdata_avgdays_copy.length<=0) seriesdata_avgdays_copy = jQuery.extend(true, [], seriesdata_avgdays);
					if(seriesdata_avgfee_copy.length<=0) seriesdata_avgfee_copy = jQuery.extend(true, [], seriesdata_avgfee);
					var aData = aoData[rowIndex]._aData;
					var ccode = aData.ccode;
					var ddesc=aData.ddesc;
					if($(this).find("i").hasClass("trend-link")){
						$("#"+tabId+" #lineChart-1").html('<img src="images/pageloading.gif" />');
						$("#"+tabId+" #lineChart-2").html('<img src="images/pageloading.gif" />');
						array_remove(legend_copy, ddesc);
						array_removeAttr(seriesdata_avgdays_copy, "name", ccode);
						array_removeAttr(seriesdata_avgfee_copy, "name", ccode);
						loadTrendChart("次均费用", xdata_avgdays, seriesdata_avgdays_copy, legend_copy, $("#"+tabId+" #lineChart-1"));
						loadTrendChart("药占比(%)", xdata_avgfee, seriesdata_avgfee_copy, legend_copy, $("#"+tabId+" #lineChart-2"));
						$(this).find("i").removeClass("trend-link");
					}else{
						$("#"+tabId+" #lineChart-1").html('<img src="images/pageloading.gif" />');
						$("#"+tabId+" #lineChart-2").html('<img src="images/pageloading.gif" />');
						var param_t = drgUI.setAjaxData(tabId);
						param_t.monitorType = "clinic";
						param_t.pargroupName = ccode;
						legend_copy.push(ddesc);
						getTrendData(param_t, "AvgFee", function(data_0){
							var seriedata_avgdays = {type: "line", smooth: true, symbol:"none", name: ccode, data:[]};
							for(o in data_0){
								seriedata_avgdays.data.push(data_0[o].QuotaValue?data_0[o].QuotaValue:0);
							}
							seriesdata_avgdays_copy.push(seriedata_avgdays);
							loadTrendChart("次均费用", xdata_avgdays, seriesdata_avgdays_copy, legend_copy, $("#"+tabId+" #lineChart-1"));
						})
						getTrendData(param_t, "DrugRatio", function(data_1){
							var seriedata_avgfee = {type: "line", smooth: true, symbol:"none", name: ccode, data:[]};
							for(o in data_1){
								seriedata_avgfee.data.push(data_1[o].QuotaValue?data_1[o].QuotaValue:0);
							}
							seriesdata_avgfee_copy.push(seriedata_avgfee);
							loadTrendChart("药占比(%)", xdata_avgfee, seriesdata_avgfee_copy, legend_copy, $("#"+tabId+" #lineChart-2"));
						})
						$(this).find("i").addClass("trend-link");
					}
				})
			})
			table.find("i.trend-link").click();
		});
	})
	getTableData("Base", "drgs","dep", function(data){
		var columns = [{"data": "ccode",
			"render": function(obj, type, full){
				return "<p><span class='drgtips' id='"+tabId+full.ccode+"' tips='"+full.ddesc+"' >"+full.ccode+"</span></p>";
			}			
		}];
		var datas = [];
		datas = datas.concat(data);
		concatTableData(quotas, datas, "drgsTable-table", columns, "drgs","dep", function(table, oSetting){
			var seriesdata_avgdays_copy = jQuery.extend(true, [], seriesdata_avgdays);
			var seriesdata_avgfee_copy = jQuery.extend(true, [], seriesdata_avgfee);
			var legend_copy = jQuery.extend(true, [], legend);
			var aoData = oSetting.aoData;
			table.find("tbody tr").each(function(i,n){
				$(n).find("td:last a").unbind();
				$(n).find("td:last a").click(function(){
					var rowIndex = $(this).attr("data-rowindex");
					if($("#"+tabId+" #lineChart-3 img").size()>0 || $("#"+tabId+" #lineChart-4 img").size()>0) return;
					if(seriesdata_avgdays_copy.length<=0) seriesdata_avgdays_copy = jQuery.extend(true, [], seriesdata_avgdays);
					if(seriesdata_avgfee_copy.length<=0) seriesdata_avgfee_copy = jQuery.extend(true, [], seriesdata_avgfee);
					var aData = aoData[rowIndex]._aData;
					var ccode = aData.ccode;
					if($(this).find("i").hasClass("trend-link")){
						$("#"+tabId+" #lineChart-3").html('<img src="images/pageloading.gif" />');
						$("#"+tabId+" #lineChart-4").html('<img src="images/pageloading.gif" />');
						array_remove(legend_copy, ccode);
						array_removeAttr(seriesdata_avgdays_copy, "name", ccode);
						array_removeAttr(seriesdata_avgfee_copy, "name", ccode);
						loadTrendChart("次均费用", xdata_avgdays, seriesdata_avgdays_copy, legend_copy, $("#"+tabId+" #lineChart-3"));
						loadTrendChart("药占比(%)", xdata_avgfee, seriesdata_avgfee_copy, legend_copy, $("#"+tabId+" #lineChart-4"));
						$(this).find("i").removeClass("trend-link");
					}else{
						$("#"+tabId+" #lineChart-3").html('<img src="images/pageloading.gif" />');
						$("#"+tabId+" #lineChart-4").html('<img src="images/pageloading.gif" />');
						var param_t = drgUI.setAjaxData(tabId);
						param_t.monitorType = "drgs";
						param_t.pardrgCode = ccode;
						legend_copy.push(ccode);
						getTrendData(param_t, "AvgFee", function(data_0){
							var seriedata_avgdays = {type: "line", smooth: true, symbol:"none", name: ccode, data:[]};
							for(o in data_0){
								seriedata_avgdays.data.push(data_0[o].QuotaValue?data_0[o].QuotaValue:0);
							}
							seriesdata_avgdays_copy.push(seriedata_avgdays);
							loadTrendChart("次均费用", xdata_avgdays, seriesdata_avgdays_copy, legend_copy,  $("#"+tabId+" #lineChart-3"));
						})
						getTrendData(param_t, "DrugRatio", function(data_1){
							var seriedata_avgfee = {type: "line", smooth: true, symbol:"none", name: ccode, data:[]};
							for(o in data_1){
								seriedata_avgfee.data.push(data_1[o].QuotaValue?data_1[o].QuotaValue:0);
							}
							seriesdata_avgfee_copy.push(seriedata_avgfee);
							loadTrendChart("药占比(%)", xdata_avgfee, seriesdata_avgfee_copy, legend_copy, $("#"+tabId+" #lineChart-4"));
						})
						$(this).find("i").addClass("trend-link");
					}
				});
			});
			table.find("i.trend-link").click();
		});
	})
	
	//添加超链接（病组结构分析） 点击监听事件
	var aHref = $("#"+tabId+"  #disGroupHref a");
	//传递最新的上级页面参数
	var myBingZuJieGouParam = $("#tabContent > .tab-pane.active").data(); 
	//设置要打开的病组结构分析的tab页唯一id值
	var aHrefTabId = 'disGroupAnalysis-'+myBingZuJieGouParam.depCode;
	aHref.unbind("click");
	aHref.bind("click", function(){
		//如果写成 var p =drgUI.setAjaxData(tabId); 则页面始终加载第一次打开时的数据
		var p = myBingZuJieGouParam;
		//父页面科室指标象限分析的tab标题为CMI和DRGs组数---跳转到医政角色病组结构分析页面
		if(p.patientGroupAnalysisPage && p.patientGroupAnalysisPage == 'yizheng'){
			openTab('/pages/yibao/fenxi/disStructureAnalysis.jsp', '病组结构分析'+"|"+p.depName,aHrefTabId, aHrefTabId,p);
		}else if(p.patientGroupAnalysisPage && p.patientGroupAnalysisPage == 'yibao'){
			//父页面科室指标象限分析的其他标题--跳转到医保角色病组结构分析页面
			openTab('/pages/yibao/fenxi/disGroupAnalysis.jsp', '病组结构分析'+"|"+p.depName,aHrefTabId, aHrefTabId,p);
		}
	});
	//	
	//将指标与数据拼接成datatables要输出的格式
	function concatTableData(newQuotas, datas, divId, columns, monitorType,specHeader, callback){
		var thead = $("#"+tabId+" #"+divId+" thead tr");
		//在病组页签中添加一列病组描述，并将该列设置为不可见，但数据导出可以导出
		if(monitorType == "drgs" ){
			thead.append("<td class='displayColumn' style='display: none;'>病组描述</td>");
			var descColumn = {
				"data": "ddesc","visible": false
			}
			columns.push(descColumn);
		}
		//循环拼接指标
		for(var o in newQuotas){
			var quota = newQuotas[o];
			if(quota.code=="ExcessCnt_F"){
				thead.append("<td style='width:50px;' >" + quota.name + "<span class='drgtips' id='"+tabId+"ExcessCnt_id' tips='次均费用超标的病例' style='color: #0072ff;'>[注]</span></td>");
			}else if(quota.code=="SpecificCnt_F"){
				thead.append("<td style='width:50px;' >" + quota.name + "<span class='drgtips' id='"+tabId+"SpecificCnt_id'  tips='次均费用>1.2*费用消耗指数*次均费用标杆的病例' style='color: #0072ff;'>[注]</span></td>");
			}else if(quota.code=="AvgFee_F"){
				thead.append("<td style='width:50px;' >" + quota.name + "<span class='drgtips' id='"+tabId+"AvgFee_id'  tips='排除特异病例后的次均费用' style='color: #0072ff;'>[注]</span></td>");
			}else if(quota.code=="DrugRatio_F"){
				thead.append("<td style='width:50px;' >" + quota.name + "<span class='drgtips' id='"+tabId+"DrugRatio_id' tips='排除特异病例后的药占比' style='color: #0072ff;'>[注]</span></td>");
			}else{
				thead.append("<td style='width:50px;'>"+quota.name+"</td>");
			}
		}
		var i=0;	
		configQuotaFlag(newQuotas[i].code,newQuotas[i].name,i,newQuotas,newQuotas[i].isLink);
		//对非基础指标列进行拼接，用递归方法解决循环与多个ajax请求异步问题
		function configQuotaFlag(value,name,cnt,array,isLink){
			if(value=="AvgFeecc"||value=="DrugRatiocc"){
				columns.push({  "data": value,
								"render": function(obj, type, full){
										if(array[cnt].value==undefined||array[cnt].value==""){
											return "-";
										}else{
											return array[cnt].value;
										}
									}
					});
				if(cnt+1<array.length){
					configQuotaFlag(array[cnt+1].code,array[cnt+1].name,cnt+1,array,array[cnt+1].isLink);
				}
				else return false;
			}else{
				if(isLink=="1"){
					columns.push({ "data": value,
						"type":"number-html",
						"render": function(obj, type, full){	
							if(full[value]=="0"||full[value]==undefined){
								return "0";
							}
							return "<a href=\"javascript:loadCaseDtl('"+full.ddesc+"|"+name+"','"+full.ccode+"','"+monitorType+"', '"+value+"')\">"+full[value]+"</a>";
						}
					});
				}
				else{
					columns.push({ "data": value,
						"render": function(obj, type, full){
							if(full[value]==undefined){
								return "-";

							}else{
								return full[value];
							}
						}});
				}
				getTableData(value, monitorType, specHeader,function(data, quotaCode){
					var data_s = [];
					data_s = data_s.concat(data);
					mergeListcc(datas, data_s,'ccode','',quotaCode);
					ajaxCount--;
				})
				if(cnt+1<array.length){
					configQuotaFlag(array[cnt+1].code,array[cnt+1].name,cnt+1,array,array[cnt+1].isLink);
				}
				else return false;
			}
		}
			
		var timer = setInterval(function(){
			if(ajaxCount==0){
				clearInterval(timer);
				if(monitorType != "dep"){
					thead.append("<td>操作</td>");
					var operationColumn = {
						"data": "OPERATION",
		            	"render" : function(obj, type, full,meta) {
		            		var trendClass = "";
		            		if(monitorType == "dep"){
		            			trendClass = " trend-link";
		            		}
		            		return "<div><a class='tr' title='趋势' data-rowindex='"+meta.row+"'><i class='fa fa-line-chart"+trendClass+"'></a></i></div>";
		            	}
					}
					columns.push(operationColumn);
				}
				var tableTitle=$("#"+tabId+" #"+divId).find(".contaotalsccq").text();
				var orderDefs1=[[1,"desc"]];
				var orderDefs2=[[2,"desc"]];
				var paramsDataTables={lengthChange:false,info:false,searching:true,tableTitle:tableTitle,columnDefs:[{orderable:false,targets:[columns.length-1]}]};
				var drawCallback= function(oSettings) {
					// 获取datatables标题,供导出时获取
					oSettings.expertName = this.find(".contaotalsccq").text();
					var table = $(this);
					callback(table, oSettings);
				}
				paramsDataTables.drawCallback=drawCallback;
				if(monitorType == "dep"){
					paramsDataTables["ordering"] = false;
					paramsDataTables.paging=false;
                    paramsDataTables.searching=false ;
				}
				if(monitorType == "drgs"){
					paramsDataTables["scrollY"] = "300px";
					paramsDataTables["order"] =orderDefs2;
				}else if(monitorType == "clinic"){
					paramsDataTables["scrollY"] = "400px";
					paramsDataTables["order"] =orderDefs1;
				}
				$("#"+tabId+" #"+divId).dataTableBasic(columns,datas,paramsDataTables);
				if(monitorType == "drgs"){
					$('.testCon').each(function(i,n){
						$(n).removeClass('testCon');
					});
				}
			}
		}, 500);
	}
	
	//根据指标发送请求获取数据
	function getTableData(quotaCode, monitorType,specHeader,callback){
		var param = drgUI.setAjaxData(tabId);
		param["monitorType"]=monitorType;
		param["specHeader"]=specHeader;
		param["quotaCode"]=quotaCode;
		param["isGetCc"]="0";
		$.post(contextPath + "/DrgsIndexCal/indexCal.dhc",param).done(function(data){
			var data = data.data;
			callback(data, quotaCode);
		})
	}
	
	//获取双指标趋势数据
	function getTrendData(param_t, quotaCode, callback){
		param_t.quotaCode = quotaCode;
		$.post(contextPath + "/ywcHome/getCMIDRGCount.dhc",param_t).done(function(data){
			var data = data.data;
			callback(data, quotaCode);
		})
	}
	
	function loadTrendChart(title, xdata, seriesdata, legend, container){
		//调公共方法组装数据
		var lines = [];
		var echartData=[];
		for(var o in legend){
			lines.push({code:'code'+o,desc:legend[o],data:[]});
		}
		for(var o in seriesdata){
			var obj=[];
			for(var j in seriesdata[o].data){
				var temp={};
				temp.ddesc=xdata[j];
				temp['code'+o]=seriesdata[o].data[j];
				obj.push(temp);
			}
			echartData.push(obj);
		}
		var chartParams={legendPosition:'bottom'}
		lineChartBasic(container, lines, echartData, title+'变化趋势','',chartParams);
	}
	
//	var quotas_tt = ["InCaseCnt", "DRGCount", "AvgFee", "DrugRatio", "CMI"];
//	var param_tt = drgUI.setAjaxData(tabId);
//	for(var o in quotas_tt){
//		var quotaCode = quotas_tt[o];
//		param_tt.quotaCode = quotaCode;
//		param_tt.type1 = "0";
//		getQuotas5(param_tt, o, function(data, o){
//			if(data && data.length>0){
//				$("#"+tabId+" #drgsTable-table-1").find("tbody tr:eq(0)").find("td").eq(Number(o)+1).html(data[0].QuotaValue);
//			}
//		})
//		param_tt.type1 = "1";
//		getQuotas5(param_tt, o, function(data, o){
//			if(data && data.length>0){
//				$("#"+tabId+" #drgsTable-table-1").find("tbody tr:eq(1)").find("td").eq(Number(o)+1).html(data[0].QuotaValue);
//			}
//		})
//	}
//	
//	function getQuotas5(param_tt, o, callback){
//		$.post(contextPath + "/DrgsIndexCal/indexCal.dhc", param_tt).done(function(data){
//			callback(data.data, o)
//		})
//	}
//	
//	$("#"+tabId+" #drgsTable-table-1").DataTable({
//		"destroy": true,
//		"paging": false, //翻页功能
//		"lengthChange": false, //改变每页显示数据数量
//		"searching": false, //过滤功能
//		"info": false, //页脚信息
//	    "stateSave": false, 
//	    "ordering": false,
//	    "pageLength": false
//	});
//	
//	//////////////////////////////////////////////////////////
//	var title=['本期覆盖病组','同期覆盖病组','本期未覆盖,仅同期覆盖病组','同期未覆盖,仅本期覆盖病组','次均费用本期值<=同期值的病组','次均费用本期值>同期值的病组'];
//	var titleCode=['this','last','thisNo','lastNo','thisSmall','thisBig'];
//	param.monitorType = "M";
//	$.post(contextPath +"/DisGroupAnalysis/drgsStructure.dhc",param).done(function(result){
//		var data = result.data;
//		$('#'+tabId+' #table').html('');
//		//本期
//		$('#'+tabId+' #table').append('<tr><td>'+title[0]+'</td><td>'+drgsCntLink(data.thisPeriod[0].DRGCNT,titleCode[0],param)+'</td>'
//				+'<td><a href="javascript:loadCaseStructure(\'thisPeriod\')" >'+dealwithInt(data.thisPeriod[0].INCASECNT)+'</a></td>'
//				+'<td>'+dealwithFloatMillion(data.thisPeriod[0].TOTALFEE)+'</td>'
//				+'<td>'+dealwithFloat(data.thisPeriod[0].AVGFEE)+'</td><td>'+dealwithFloat(data.thisPeriod[0].CMI)+'</td>'
//				+'<td>'+dealwithFloat(data.thisPeriod[0].TOTALWEIGHT)+'</td><td>'+overproofDrgsCntLink(data.thisPeriod[0].OVERFEECNT,titleCode[0],param)+'</td></tr>');
//		//同期
//		$('#'+tabId+' #table').append('<tr><td>'+title[1]+'</td><td>'+drgsCntLink(data.lastPeriod[0].DRGCNT,titleCode[1],param)+'</td>'
//				+'<td><a href="javascript:loadCaseStructure(\'lastPeriod\')" >'+dealwithInt(data.lastPeriod[0].INCASECNT)+'</a></td>'
//				+'<td>'+dealwithFloatMillion(data.lastPeriod[0].TOTALFEE)+'</td>'
//				+'<td>'+dealwithFloat(data.lastPeriod[0].AVGFEE)+'</td><td>'+dealwithFloat(data.lastPeriod[0].CMI)+'</td>'
//				+'<td>'+dealwithFloat(data.lastPeriod[0].TOTALWEIGHT)+'</td><td>'+overproofDrgsCntLink(data.lastPeriod[0].OVERFEECNT,titleCode[1],param)+'</td></tr>');
//		//仅同期
//		$('#'+tabId+' #table').append('<tr><td>'+title[2]+'</td><td>'+drgsCntLink(data.onlyLastPeriod[0].DRGCNT,titleCode[2],param)+'</td>'
//				+'<td><a href="javascript:loadCaseStructure(\'onlyLastPeriod\')" >'+dealwithInt(data.onlyLastPeriod[0].INCASECNT)+'</a></td>'
//				+'<td>'+dealwithFloatMillion(data.onlyLastPeriod[0].TOTALFEE)+'</td>'
//				+'<td>'+dealwithFloat(data.onlyLastPeriod[0].AVGFEE)+'</td><td>'+dealwithFloat(data.onlyLastPeriod[0].CMI)+'</td>'
//				+'<td>'+dealwithFloat(data.onlyLastPeriod[0].TOTALWEIGHT)+'</td><td>'+overproofDrgsCntLink(data.onlyLastPeriod[0].OVERFEECNT,titleCode[2],param)+'</td></tr>');
//		//仅本期
//		$('#'+tabId+' #table').append('<tr><td>'+title[3]+'</td><td>'+drgsCntLink(data.onlyThisPeriod[0].DRGCNT,titleCode[3],param)+'</td>'
//				+'<td><a href="javascript:loadCaseStructure(\'onlyThisPeriod\')" >'+dealwithInt(data.onlyThisPeriod[0].INCASECNT)+'</a></td>'
//				+'<td>'+dealwithFloatMillion(data.onlyThisPeriod[0].TOTALFEE)+'</td>'
//				+'<td>'+dealwithFloat(data.onlyThisPeriod[0].AVGFEE)+'</td><td>'+dealwithFloat(data.onlyThisPeriod[0].CMI)+'</td>'
//				+'<td>'+dealwithFloat(data.onlyThisPeriod[0].TOTALWEIGHT)+'</td><td>'+overproofDrgsCntLink(data.onlyThisPeriod[0].OVERFEECNT,titleCode[3],param)+'</td></tr>');
//		//本期小
//		$('#'+tabId+' #table').append('<tr><td>'+title[4]+'</td><td>'+drgsCntLink(data.thisPeriodLittle[0].DRGCNT,titleCode[4],param)+'</td>'
//				+'<td><a href="javascript:loadCaseStructure(\'thisPeriodLittle\')" >'+dealwithInt(data.thisPeriodLittle[0].INCASECNT)+'</a></td>'
//				+'<td>'+dealwithFloatMillion(data.thisPeriodLittle[0].TOTALFEE)+'</td>'
//				+'<td>'+dealwithFloat(data.thisPeriodLittle[0].AVGFEE)+'</td><td>'+dealwithFloat(data.thisPeriodLittle[0].CMI)+'</td>'
//				+'<td>'+dealwithFloat(data.thisPeriodLittle[0].TOTALWEIGHT)+'</td><td>'+overproofDrgsCntLink(data.thisPeriodLittle[0].OVERFEECNT,titleCode[4],param)+'</td></tr>');
//		//本期大
//		$('#'+tabId+' #table').append('<tr><td>'+title[5]+'</td><td>'+drgsCntLink(data.thisPeriodLarge[0].DRGCNT,titleCode[5],param)+'</td>'
//				+'<td><a href="javascript:loadCaseStructure(\'thisPeriodLarge\')" >'+dealwithInt(data.thisPeriodLarge[0].INCASECNT)+'</a></td>'
//				+'<td>'+dealwithFloatMillion(data.thisPeriodLarge[0].TOTALFEE)+'</td>'
//				+'<td>'+dealwithFloat(data.thisPeriodLarge[0].AVGFEE)+'</td><td>'+dealwithFloat(data.thisPeriodLarge[0].CMI)+'</td>'
//				+'<td>'+dealwithFloat(data.thisPeriodLarge[0].TOTALWEIGHT)+'</td><td>'+overproofDrgsCntLink(data.thisPeriodLarge[0].OVERFEECNT,titleCode[5],param)+'</td></tr>');
//	});
//	
//	function drgsCntLink(number,code,param){
//		if (number!=null && "" != number && number>0) {
//			return '<a href="javascript:showDRGsDetail(\'null\',\''+param.depCode+'\',\''+param.dateFrom+'\',\''+param.dateTo+'\',\''+code+'\');bdclose(\'detail-popover\')">'+number+'</a>';
//		} 
//		return "";
//	}
//
//	function overproofDrgsCntLink(number,code,param){
//		if (number!=null && "" != number && number>0) {
//			return '<a href="javascript:showOverproofDRGsDetail(\'null\',\''+param.depCode+'\',\''+param.dateFrom+'\',\''+param.dateTo+'\',\''+code+'\');bdclose(\'detail-popover-overproof\')">'+number+'</a>';
//		} 
//		return 0;
//	}
//
//	//四舍五入
//	function dealwithInt(number){
//		if (number!=null && "" != number) {
//			return number;
//		} 
//		return "";
//	}
//	function dealwithFloat(number){
//		if (number!=null&& "" != number) {
//			return Number(number).toFixed(2);
//		}
//		return "";
//	}
//	function dealwithFloatMillion(number){
//		if (number!=null&& "" != number) {
//			return formatNumber(Number(number/10000).toFixed(2));
//		}
//		return "";
//	}
})
////加载病例明细
//function loadCaseStructure(monitorType){
//	var param = drgUI.setAjaxData(tabId);
//	param.monitorType = monitorType;
//	var depGroupCode=param.depGroupCode;
//	var depCode=param.depCode;
//	var wardCode=param.wardCode;
//	$.post(contextPath+'/DisGroupAnalysis/loadCase.dhc',param).done(function(result){
//		if(depCode){
//			depCode = depCode.replace(/,/g, '');
//		}
//		openTab('/pages/yizheng/fenxi/caselist.jsp', '病例明细',monitorType+depGroupCode+depCode+wardCode+"structurecaselist",monitorType+depGroupCode+depCode+wardCode+"structurecaselist",{param:param, data:result.data});
//	});
//}
////加载病组详情表格
//function showDRGsDetail(queryType){
//	var param = drgUI.setAjaxData(tabId);//获取当前页面 初始参数
//	
//	var dateFrom = param.dateFrom;
//	var dateTo = param.dateTo;
//	$("html, body").animate({scrollTop:0},200);
//	$('#'+tabId+' #drg-detail').css('height','102px');
//	$('#'+tabId+' #detail_progress').css('width','0');
//	setTimeout(function(){
//		$('#'+tabId+' #detail_progress').css({'transition':'width 10s ease','width':'99%'});
//	}, 20);
//	$('#'+tabId+' .thisyear').html(dateFrom.substring(0,4));
//	$('#'+tabId+' .lastyear').html(dateFrom.substring(0,4)-1);
//	//弹出层详细
//	$('#'+tabId+' #drg-detail tbody').html('');
//	$('#'+tabId+' #detail-popover thead').css({'position':'','top':''});
//	param.queryType = queryType;
//	$.post(contextPath +"/DisGroupAnalysis/drgsDetail.dhc",param).done(function(result){
//		setTimeout(function() {
//			$('#'+tabId+' #detail_progress').css({'transition':'width .5s ease','width':'100%'});
//		}, 20);	 
//		$.each(result.data,function(i,n){
//			var avgDaysStr='';
//			var avgDaysStr_l='';
//			if (n["LAVGDAY"]==null || n["LAVGDAY"]==0) {
//				avgDaysStr_l=Number(n["LAVGDAY"]).toFixed(1);
//				avgDaysStr='<span style="float:left;width:38px;text-align:right;">'+Number(n["AVGDAY"]).toFixed(1)+'</span>';
//			} else if (n["AVGDAY"]-n["LAVGDAY"]>0) {
//				avgDaysStr='<span style="float:left;width:38px;text-align:right;">'+Number(n["AVGDAY"]).toFixed(1)
//						+'</span><span style="float:right;width:40px;text-align:left;"><i title="高于去年" style="color:red;font-weight:bold;">↑</i>'
//						+'<small style="color:#d9534f;">'+Number((n["AVGDAY"]-n["LAVGDAY"])*100/n["LAVGDAY"]).toFixed(0)+'%</small></span>';
//				avgDaysStr_l=Number(n["LAVGDAY"]).toFixed(1);
//			} 
//			else if(n["AVGDAY"]-n["LAVGDAY"]==0)
//			{
//				avgDaysStr='<span style="float:left;width:38px;text-align:right;">'+Number(n["AVGDAY"]).toFixed(1)
//				+'</span><span style="float:right;width:40px;text-align:left;"><i title="等于去年" style="color:#FFA500;font-weight:bold;">-</i>'
//				+'<small style="color:#FFA500;">'+Number((n["AVGDAY"]-n["LAVGDAY"])*100/n["LAVGDAY"]).toFixed(0)+'%</small></span>';
//				avgDaysStr_l=Number(n["LAVGDAY"]).toFixed(1);
//			}
//			else {
//				avgDaysStr='<span style="float:left;width:38px;text-align:right;">'+Number(n["AVGDAY"]).toFixed(1)
//						+'</span><span style="float:right;width:40px;text-align:left;"><i title="低于去年" style="color:green;font-weight:bold;">↓</i>'
//						+'<small style="color:#5cb85c;">'+Number((n["LAVGDAY"]-n["AVGDAY"])*100/n["LAVGDAY"]).toFixed(0)+'%</small></span>';
//				avgDaysStr_l=Number(n["LAVGDAY"]).toFixed(1);
//			}
//			if (n["LAVGFEE"]==null || n["LAVGFEE"]==0) { 
//				$('#'+tabId+' #drg-detail tbody').append('<tr><td width="80"">'+n["DRGCODE"]+'</td><td width="318" id="'+n["DRGCODE"]+'">'+(n["DRGDESC"]==null?'':n["DRGDESC"])+'</td>'
//						+'<td  data-drgsort="'+n["DRGCODE"]+'" width="48">'+formatNumber(Number(n["LASTORDER"]).toFixed(0))+'</td><td data-drg="'+n["DRGCODE"]+'" width="80">'+formatNumber(Number(n["LPCNT"]).toFixed(0))+'</td><td width="48">'+formatNumber(Number(n["THISORDER"]).toFixed(0))+'</td><td width="80">'+formatNumber(Number(n["TPCNT"]).toFixed(0))+'</td>'
//						+'<td width="100">'+formatNumber(Number(n["LAVGFEE"]).toFixed(0))+'</td><td width="100"><span style="float:left;width:48px;text-align:right;">'+formatNumber(Number(n["AVGFEE"]).toFixed(0))+'</span></td>'
//						+'<td width="80">'+avgDaysStr_l+'</td><td width="80">'+avgDaysStr+'</td>'
//						+'<td>'+(n["WEIGHT"]==null?'':n["WEIGHT"])+'</td></tr>');
//			}else if (n["AVGFEE"]-n["LAVGFEE"]>0) {
//				$('#'+tabId+' #drg-detail tbody').append('<tr class="upTR"><td width="80">'+n["DRGCODE"]+'</td><td width="318" id="'+n["DRGCODE"]+'">'+(n["DRGDESC"]==null?'':n["DRGDESC"])+'</td>'
//						+'<td data-drgsort="'+n["DRGCODE"]+'" width="48">'+formatNumber(Number(n["LASTORDER"]).toFixed(0))+'</td><td data-drg="'+n["DRGCODE"]+'" width="80">'+formatNumber(Number(n["LPCNT"]).toFixed(0))+'</td><td width="48">'+formatNumber(Number(n["THISORDER"]).toFixed(0))+'</td><td width="80">'+formatNumber(Number(n["TPCNT"]).toFixed(0))+'</td>'
//						+'<td width="100">'+formatNumber(Number(n["LAVGFEE"]).toFixed(0))+'</td><td width="100"><span style="float:left;width:48px;text-align:right;">'+formatNumber(Number(n["AVGFEE"]).toFixed(0))
//						+'</span><span style="float:right;width:50px;text-align:left;"><i title="高于去年" style="color:red;font-weight:bold;">↑</i>'
//						+'<small style="color:#d9534f;">'+Number((n["AVGFEE"]-n["LAVGFEE"])*100/n["LAVGFEE"]).toFixed(0)+'%</small></span></td>'
//						+'<td width="80">'+avgDaysStr_l+'</td><td width="80">'+avgDaysStr+'</td>'
//						+'<td>'+(n["WEIGHT"]==null?'':n["WEIGHT"])+'</td></tr>');
//			}else if (n["AVGFEE"]-n["LAVGFEE"]==0) {
//				$('#'+tabId+' #drg-detail tbody').append('<tr class="upTR"><td width="80">'+n["DRGCODE"]+'</td><td width="318" id="'+n["DRGCODE"]+'">'+(n["DRGDESC"]==null?'':n["DRGDESC"])+'</td>'
//						+'<td data-drgsort="'+n["DRGCODE"]+'" width="48">'+formatNumber(Number(n["LASTORDER"]).toFixed(0))+'</td><td data-drg="'+n["DRGCODE"]+'" width="80">'+formatNumber(Number(n["LPCNT"]).toFixed(0))+'</td><td width="48">'+formatNumber(Number(n["THISORDER"]).toFixed(0))+'</td><td width="80">'+formatNumber(Number(n["TPCNT"]).toFixed(0))+'</td>'
//						+'<td width="100">'+formatNumber(Number(n["LAVGFEE"]).toFixed(0))+'</td><td width="100"><span style="float:left;width:48px;text-align:right;">'+formatNumber(Number(n["AVGFEE"]).toFixed(0))
//						+'</span><span style="float:right;width:50px;text-align:left;"><i title="等于去年" style="color:#FFA500;font-weight:bold;">-</i>'
//						+'<small style="color:#FFA500;">'+Number((n["AVGFEE"]-n["LAVGFEE"])*100/n["LAVGFEE"]).toFixed(0)+'%</small></span></td>'
//						+'<td width="80">'+avgDaysStr_l+'</td><td width="80">'+avgDaysStr+'</td>'
//						+'<td>'+(n["WEIGHT"]==null?'':n["WEIGHT"])+'</td></tr>');
//			}
//			else {
//				$('#'+tabId+' #drg-detail tbody').append('<tr class="downTR"><td width="80"">'+n["DRGCODE"]+'</td><td width="318" id="'+n["DRGCODE"]+'">'+(n["DRGDESC"]==null?'':n["DRGDESC"])+'</td>'
//						+'<td  data-drgsort="'+n["DRGCODE"]+'" width="48">'+formatNumber(Number(n["LASTORDER"]).toFixed(0))+'</td><td data-drg="'+n["DRGCODE"]+'" width="80">'+formatNumber(Number(n["LPCNT"]).toFixed(0))+'</td><td width="48">'+formatNumber(Number(n["THISORDER"]).toFixed(0))+'</td><td width="80">'+formatNumber(Number(n["TPCNT"]).toFixed(0))+'</td>'
//						+'<td width="100">'+formatNumber(Number(n["LAVGFEE"]).toFixed(0))+'</td><td width="100"><span style="float:left;width:48px;text-align:right;">'+formatNumber(Number(n["AVGFEE"]).toFixed(0))
//						+'</span><span style="float:right;width:50px;text-align:left;"><i title="低于去年" style="color:green;font-weight:bold;">↓</i>'
//						+'<small style="color:#5cb85c;">'+Number((n["LAVGFEE"]-n["AVGFEE"])*100/n["LAVGFEE"]).toFixed(0)+'%</small></span></td>'
//						+'<td width="80">'+avgDaysStr_l+'</td><td width="80">'+avgDaysStr+'</td>'
//						+'<td>'+(n["WEIGHT"]==null?'':n["WEIGHT"])+'</td></tr>');
//			}
//		});
//		//遍历drgs添加描述   
////		$.each(drgs,function(i,n){
////			$('#'+tabId+' td[id]').each(function(){
////				var tid=$(this).attr('id');
////				if (tid==n.drgCode) {
////					$('#'+tabId+' #'+tid).html(n.drgDesc);
////				}
////			});
////		});
//		
//	/*	//拼接drgCode-personNum数组
//		drgSortArray.length=0;//清空数组
//		$('#'+tabId+' td[data-drg]').each(function(i){
//			drgSortArray[i]=$(this).attr('data-drg')+'-'+$(this).html();
//		});
//		//从大到小排序drg数组
//		drgSortArray.sort(compareFunc);*/
//	//	sortListMap(result.data, LASTORDER, desc); 
//		//生成序号
//	/*	for (var i = 0; i < drgSortArray.length; i++) {
//			var drgCodeStr=drgSortArray[i]
//			var drgCode=drgCodeStr.substring(0,drgCodeStr.indexOf('-'));//截取drgCode
//			$('#'+tabId+' td[data-drgsort="'+drgCode+'"').html(i+1);
//		}*/
//		
//		
//		//启用tooltip
////		$("[data-toggle='tooltip']").tooltip();
//		var detailHeight=$('#'+tabId+' #drg-detail table').css('height');
//		detailHeight = Number(detailHeight.substring(0,detailHeight.indexOf('px')))+40;
//		$('#'+tabId+' #drg-detail').css('height',detailHeight+'px');
//		
//		//表格导出功能
//		var uri  = 'data:application/vnd.ms-excel;base64,',
//    template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40"><head><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
//    base64   = function (s) { return window.btoa(unescape(encodeURIComponent(s))) },
//    format   = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) },
//    data      = { worksheet: name || '病组详情', table: document.getElementById('detailTable').innerHTML };
//    document.getElementById('downloadBtn').href = uri + base64(format(template, data))
//	});
//	
//	$('#'+tabId+' #detail-popover').addClass('popoverActive');
//}
//
////加载费用超标病组详情表格
//function showOverproofDRGsDetail(queryType){
//	var param = drgUI.setAjaxData(tabId);//获取当前页面 初始参数
//	var dateFrom = param.dateFrom;
//	var dateTo = param.dateTo;
//	$("html, body").animate({scrollTop:0},200);
//	$('#'+tabId+' #drg-detail-overproof').css('height','102px');
//	$('#'+tabId+' #detail_progress_overproof').css('width','0');
//	setTimeout(function(){
//		$('#'+tabId+' #detail_progress_overproof').css({'transition':'width 10s ease','width':'99%'});
//	}, 20);
//	if(queryType=="last" || queryType=="thisNo"){
//		$('#'+tabId+' .thisyear').html(dateFrom.substring(0,4)-1);
//	}else{
//		$('#'+tabId+' .thisyear').html(dateFrom.substring(0,4));
//	}
//	
//	//弹出层详细
//	$('#'+tabId+' #drg-detail-overproof tbody').html('');
//	$('#'+tabId+' #detail-popover-overproof thead').css({'position':'','top':''});
//	param.queryType = queryType;
//	$.post(contextPath +"/DisGroupAnalysis/overproofDrgsDetail.dhc",param).done(function(result){
//				setTimeout(function(){
//					$('#'+tabId+' #detail_progress_overproof').css({'transition':'width .5s ease','width':'100%'});
//				}, 20);	 
//				$.each(result.data,function(i,n){
//					var avgDaysStr='';
//					var avgDaysStr_l='';
//					var str = '';
//					str += '<tr>';
//					str += '	<td>'+n["DRGCODE"]+'</td>';
//					str += '	<td id="'+n["DRGCODE"]+'">'+(n["DRGDESC"]==null?'':n["DRGDESC"])+'</td>';
//					str += '	<td>'+(i+1)+'</td>';
//					str += '	<td>'+formatNumber(Number(n["INCASECNT"]).toFixed(0))+'</td>';
//					str += '	<td>'+(n["AVGFEE"]==null?n["AVGFEE"]:formatNumber(Number(n["AVGFEE"]).toFixed(2)))+'</td>';
//					str += '	<td>'+(n["AS_AVG_FEE"]==null?'':formatNumber(Number(n["AS_AVG_FEE"]).toFixed(2)))+'</td>';
//					str += '	<td>'+(n["AVGDAY"]==null?'':Number(n["AVGDAY"]).toFixed(2))+'</td>';
//					str += '	<td>'+(n["AS_AVG_DAYS"]==null?'':Number(n["AS_AVG_DAYS"]).toFixed(2))+'</td>';
//					str += '	<td>'+(n["WEIGHT"]==null?'':Number(n["WEIGHT"]).toFixed(2))+'</td>';
//					str += '</tr>';
//					$('#'+tabId+' #drg-detail-overproof tbody').append(str);
//					
//				});
//				
//				//启用tooltip
//		//		$("[data-toggle='tooltip']").tooltip();
//				var detailHeight=$('#drg-detail-overproof table').css('height');
//				detailHeight = Number(detailHeight.substring(0,detailHeight.indexOf('px')))+40;
//				$('#'+tabId+' #drg-detail-overproof').css('height',detailHeight+'px');
//				
//				//表格导出功能
//				var uri  = 'data:application/vnd.ms-excel;base64,',
//		        template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40"><head><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
//		        base64   = function (s) { return window.btoa(unescape(encodeURIComponent(s))) },
//		        format   = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) },
//		        data      = { worksheet: name || '病组详情', table: document.getElementById('detailTableOverproof').innerHTML };
//		        document.getElementById('downloadBtn1').href = uri + base64(format(template, data))
//			});
//	
//	$('#'+tabId+' #detail-popover-overproof').addClass('popoverActive');
//}
//
//drgs明细弹框关闭事件
function close(){
	$('#'+tabId+' #detail-popover').removeClass('popoverActive');
	$('#'+tabId+' #detail-popover-overproof').removeClass('popoverActive');
}

function bdclose(id){ //自定义一个函数这个函数只关闭弹的窗口，
	$('#'+tabId+' #'+id+'').click(function(event){
		 event.stopPropagation();//不再派发事件。
	})
	$('body').click(function(event){
		var _con = $('#'+tabId+' #'+id+'');   // 设置目标区域				
    	if(!_con.is(event.target) && _con.has(event.target).length === 0){ // Mark 1
			close(); //这个就是调用关闭弹窗口的函数
	    }
    });
}
